﻿<!--#include file="conn.asp"#-->
<!--#include file="sessao.asp"#-->
<!--#include file="getsessao.asp"#-->
<!--#include file="fn_combo.asp"#-->
<!--#include file="fn_table.asp"#-->
<%
Select Case request("acao")
	Case "getInformativos"
		getInformativos()
	Case "getInformativosData"
		getInformativosData()
	Case "getDatasAgendamento"
		getDatasAgendamento()
	Case "setRascunhoInformativo"
		setRascunhoInformativo()
End Select

Sub getInformativos()
	Dim db_string
	
	db_string = "SELECT "
	db_string = db_string & request("top")
	db_string = db_string & " comunicado AS [Comunicado],"
	db_string = db_string & " hora AS [Hora],"
	db_string = db_string & " desc_status_informativo AS [Status],"
	db_string = db_string & " relatorio AS [Ação]"
	db_string = db_string & " FROM informativos.vw_informativos"
	db_string = db_string & " WHERE 1=1"

	if request("cod_status_informativo") <> "0" then
		db_string = db_string & " AND cod_status_informativo = "&request("cod_status_informativo")
	end if

	if request("dt") <> "" then
		db_string = db_string & " AND CONVERT(DATE,dt_agendamento_envio) = '"&request("dt")&"'"
	end if	

	db_string = db_string & " ORDER BY hora desc,comunicado"
	
	Dim pg_sel
	if request("pagina_selecionada") = "" then
		pg_sel = 1
	else
		pg_sel = cdbl(request("pagina_selecionada"))
	end if

	response.write Table("list", db_string, "tabela", request("paginacao"), pg_sel, 5, "getInformativos('"&request("cod_status_informativo")&"','"&request("spam_destino")&"','"&request("top")&"','"&request("dt")&"','"&request("do")&"','"&request("paginacao")&"',!@#);")				

End Sub

Sub getInformativosData()
	Dim db_string
	
	db_string = "SELECT "
	db_string = db_string & request("top")
	db_string = db_string & " comunicado AS [Comunicado],"
	db_string = db_string & " data AS [Data],"
	db_string = db_string & " hora AS [Hora],"
	db_string = db_string & " desc_status_informativo AS [Status],"
	db_string = db_string & " relatorio AS [Ação]"
	db_string = db_string & " FROM informativos.vw_informativos"
	db_string = db_string & " WHERE 1=1"

	if request("cod_status_informativo") <> "0" then
		db_string = db_string & " AND cod_status_informativo = "&request("cod_status_informativo")
	end if

	if request("dt") <> "" then
		db_string = db_string & " AND CONVERT(DATE,dt_agendamento_envio) = '"&request("dt")&"'"
	end if	

	db_string = db_string & " ORDER BY data_convertida desc,hora desc,comunicado"

	Dim pg_sel
	if request("pagina_selecionada") = "" then
		pg_sel = 1
	else
		pg_sel = cdbl(request("pagina_selecionada"))
	end if

	response.write Table("list", db_string, "tabela", request("paginacao"), pg_sel, 5, "getInformativos('"&request("cod_status_informativo")&"','"&request("spam_destino")&"','"&request("top")&"','"&request("dt")&"','"&request("do")&"','"&request("paginacao")&"',!@#);")

End Sub

Sub getUsuarios()
	Dim db_string
	db_string = "SELECT u.nome [Nome]," 
	db_string = db_string & "       u.matricula [Matricula],"
	db_string = db_string & "       ei.email [E-mail]"
	db_string = db_string & " FROM   informativos.tb_informativos AS i"
	db_string = db_string & "       INNER JOIN informativos.tb_envio_informativos AS ei"
	db_string = db_string & "               ON i.cod_informativo = ei.cod_informativo"
	db_string = db_string & "       INNER JOIN informacao.tb_usuarios AS u"
	db_string = db_string & "               ON u.cod_usuario = ei.cod_usuario"
	db_string = db_string & " WHERE i.cod_informativo = "&request("cod_informativo")
	if request("condicao") <> "" then
		db_string = db_string & request("condicao")
	end if
	db_string = db_string & " ORDER BY u.nome"
	response.write Table("list", db_string, "tabela", true, 1, 10, request("pagina_funcao"))	
End Sub

Sub setRascunhoInformativo()
	Dim db_string
	if request("cod_informativo") <> "" then
		db_string = "UPDATE informativos.tb_informativos SET cod_status_informativo = 3 WHERE cod_informativo = "&request("cod_informativo")
		executeQuery(db_string)
		response.write "True"
	else
		response.write "False"
	end if
End Sub


Sub getDatasAgendamento()
	Dim db_string
	Dim rsDatas

	db_string = "SELECT datas FROM informativos.vw_datas_calendario order by datas"
	set rsDatas = getRs(db_string)

	if not rsDatas.eof then
		retorno = "{success : true, data: {"
	    retorno = retorno & " 'datas_disp':'"&rsDatas("datas")&"' }"
		retorno = retorno & "}"
	End If
	rsDatas.close
	response.write retorno
End Sub

%>
